//
// Created by YE on 2024/1/6.
//

#ifndef YCH_INTERPRETER_YCH_ERROR_H
#define YCH_INTERPRETER_YCH_ERROR_H

#include "../common/ych.h"

typedef YCH_ERROR_STATE Error_State;
typedef YCH_STRING String;
typedef struct Error {
public:
    Error_State errorState;
    String errorInfo;
} Error;
typedef std::stack<Error> Error_Stack;
extern Error_Stack errorStack;

void throw_error(Error_State errorState, const String &errorInfo);
/*
#include <stdio.h>
#include <setjmp.h>

jmp_buf exception_buffer;

void handle_exception() {
    printf("Exception caught!\n");
}

int divide(int a, int b) {
    if (b == 0) {
        // 发生除零异常，跳转到异常处理代码块
        longjmp(exception_buffer, 1);
    }
    return a / b;
}

int main() {
    // 设置异常处理点
    if (setjmp(exception_buffer) == 0) {
        // 尝试执行可能抛出异常的代码
        int result = divide(10, 0);
        printf("Result: %d\n", result);
    } else {
        // 异常处理代码块
        handle_exception();
    }

    return 0;
}
 * */
#endif //YCH_INTERPRETER_YCH_ERROR_H
